package com.dht.xiao.jianye.command.base.util;

import java.io.IOException;
import java.io.LineNumberReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;

/**
 * @author :      fangbingran
 * @aescription : todo(这里用一句话描述这个类的作用)
 * @date :        2019/06/13  20:14
 */
public class CommonUtil {
    public static String getThrowableStrRep(Throwable throwable) {
        if (throwable == null) {
            return null;
        } else {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            throwable.printStackTrace(pw);
            pw.flush();
            LineNumberReader reader = new LineNumberReader(new StringReader(sw.toString()));
            ArrayList lines = new ArrayList();

            try {
                for(String line = reader.readLine(); line != null; line = reader.readLine()) {
                    lines.add(line);
                }
            } catch (IOException var6) {
                lines.add(var6.toString());
            }

            String[] rep = new String[lines.size()];
            lines.toArray(rep);
            return Arrays.toString(rep);
        }
    }
}
